widget: Add gtk_widget_get_size()
authorBenjamin Otte <otte@redhat.com>
Sat, 19 Oct 2019 03:15:15 +0000 (05:15 +0200)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 30 May 2020 14:48:02 +0000 (10:48 -0400)
A little bit of convenience.

docs/reference/gtk/gtk4-sections.txt
gtk/gtkwidget.c
gtk/gtkwidget.h

index 085b77d7cae2b06ca1600e25098e39814920a925..97d20ece0bb92a15aced3bc6f78515a25af10970 100644 (file)
@@ -4011,6 +4011,7 @@ gtk_widget_get_allocation
 gtk_widget_get_allocated_baseline
 gtk_widget_get_width
 gtk_widget_get_height
+gtk_widget_get_size
 gtk_widget_compute_bounds
 gtk_widget_compute_transform
 gtk_widget_compute_point
index 27bec07c231895070e052379d2cadaea053ddd2a..f667a5d8d42d7ea2f495f2580f60ac3aa7d1421f 100644 (file)
@@ -12254,6 +12254,31 @@ gtk_widget_get_height (GtkWidget *widget)
   return priv->height;
 }
 
+/**
+ * gtk_widget_get_size:
+ * @widget: a #GtkWidget
+ * @orientation: the orientation to query
+ *
+ * Returns the content width or height of the widget, depending on @orientation.
+ * This is equivalent to calling gtk_widget_get_width() for %GTK_ORIENTATION_HORIZONTAL
+ * or gtk_widget_get_height() for %GTK_ORIENTATION_VERTICAL, but can be used when
+ * writing orientation-independent code, such as when implementing #GtkOrientable
+ * widgets.
+ *
+ * Returns: The size of @widget in @orientation.
+ */
+int
+gtk_widget_get_size (GtkWidget      *widget,
+                     GtkOrientation  orientation)
+{
+  g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
+
+  if (orientation == GTK_ORIENTATION_HORIZONTAL)
+    return gtk_widget_get_width (widget);
+  else
+    return gtk_widget_get_height (widget);
+}
+
 /**
  * gtk_widget_class_set_layout_manager_type:
  * @widget_class: class to set the layout manager type for
index 278c1228c7192817a923a7312428d8488b77dbbc..de0cf97ed8192b38f70af09852a463ae7fe1128f 100644 (file)
@@ -525,6 +525,9 @@ GDK_AVAILABLE_IN_ALL
 int                   gtk_widget_get_width              (GtkWidget     *widget);
 GDK_AVAILABLE_IN_ALL
 int                   gtk_widget_get_height             (GtkWidget     *widget);
+GDK_AVAILABLE_IN_ALL
+int                   gtk_widget_get_size               (GtkWidget     *widget,
+                                                         GtkOrientation orientation);
 
 GDK_AVAILABLE_IN_ALL
 gboolean   gtk_widget_child_focus         (GtkWidget           *widget,